package dao;

import hbt.HibernateUtil;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import beanCarta.Carta;
import beanCarta.ItemCarta;
import beanCarta.Producto;
import beanCuenta.Account;

public class CartaDAO {

	private static CartaDAO iCartaDAO;
	private static SessionFactory sf = null;
	
	public static CartaDAO getInstance(){
		if(iCartaDAO == null){
			iCartaDAO = new CartaDAO();
			sf = HibernateUtil.getSessionFactory();
		}
		return iCartaDAO;
	}

	public void guardarCarta(Carta c) {
		Session session = sf.openSession();
		session.beginTransaction();
		session.persist(c);
		session.getTransaction().commit();
		session.close();		
	}

	public void guardarItems(ItemCarta i1) {
		Session session = sf.openSession();
		session.beginTransaction();
		session.persist(i1);
		session.getTransaction().commit();
		session.close();		
	}

	public void guardarProducto(Producto producto) {
		Session session = sf.openSession();
		session.beginTransaction();
		session.persist(producto);
		session.getTransaction().commit();
		session.close();
	}

	public Carta getCarta() {
		Session session = sf.openSession();
		return (Carta) session.createQuery("from Carta").list().get(0);
	}		
	public Producto traerProducto(String codigoProducto) {
		Session session = sf.openSession();
		return (Producto) session.createQuery("from Producto").list().get(0);
	}
}
